<?php

class UserModel extends Model {
	
	#------------------
	# 建立用户拍卖锁
	public function auctionLock($u_id, $au_id) {
		$_u ['u_id'] = $u_id;
		$_u_s ['u_lock_auid'] = $au_id;
		M ( 'User' )->where ( $_u )->data ( $_u_s )->save ();
	}
	
	# 取消用户拍卖锁
	public function auctionUnLock($u_id) {
		$_u ['u_id'] = $u_id;
		$_u_s ['u_lock_auid'] = 0;
		M ( 'User' )->where ( $_u )->data ( $_u_s )->save ();
	}
	
	#------------------
	
	# 打卡~更新打卡记录
	public function updateCarddays($user, $u_run_carddays) {
		$_u ['u_id'] = $user ['u_id'];
		$_u_s ['u_carddays'] = $user ['u_carddays'] + 1;
		$_u_s ['u_run_carddays'] = $u_run_carddays;
		M ( 'User' )->where ( $_u )->data ( $_u_s )->save ();
	}
	
	#-------------------
	
	# 修改用户资料
	public function modify($u_id) {
		$result = $this->checkPass ();
		if ($result == 1)
			$result = $this->userModify ( $u_id );
		if ($result == 1)
			update_session ( $this->_userinfo );
		return $result;
	}
	
	private function checkPass() {
		return $_REQUEST ['u_password'] != $_REQUEST ['u_repassword'] ? - 2 : 1;
	}
	
	private function userModify($u_id) {
		$_con ['u_id'] = $u_id;
		if ($_REQUEST ['u_password'])
			$_udata ['u_password'] = md5 ( $_REQUEST ['u_password'] );
		$_udata ['u_liantong'] = $_REQUEST ['u_liantong'];
		$_udata ['u_address'] = $_REQUEST ['u_address'];
		$result = M ( 'User' )->where ( $_con )->data ( $_udata )->save ();
		$this->_userinfo = M ( 'User' )->where ( $_con )->find ();
		return $this->_userinfo ['u_id'] ? 1 : - 3;
	}

}
?>